﻿Public Class cCaja
    Private drCaja As dsCaja.CAJ_CAJASRow
    Private iSucursal As cSedes
    Private recovery As String
    Public Sub New(ByVal IdCaja As String)
        Try
            Dim daCaja As New dsCajaTableAdapters.CAJ_CAJASTableAdapter
            Dim dtCaja As dsCaja.CAJ_CAJASDataTable = daCaja.GetDataByIdCaja(IdCaja)
            If dtCaja.Rows.Count > 0 Then
                drCaja = dtCaja.Rows(0)
                iSucursal = New cSedes(drCaja.IDSUCURSAL)
            Else
                Throw New Exception("Caja no existe favor verificar e intentar de nuevo")
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public ReadOnly Property IdCaja() As String
        Get
            Return drCaja.IDCAJA
        End Get
    End Property
    Public ReadOnly Property Descripcion() As String
        Get
            Return drCaja.DESCRIPCION
        End Get
    End Property
    Public ReadOnly Property Sucursal() As cSedes
        Get
            Return iSucursal
        End Get
    End Property
    Public ReadOnly Property FechaUltimoCuadre() As Date
        Get
            If drCaja.IsFECHAULTCUADRENull Then
                Return Date.Today.AddYears(-100)
            Else
                Return drCaja.FECHAULTCUADRE
            End If
        End Get
    End Property
    Public ReadOnly Property Saldo() As Double
        Get
            Return drCaja.SALDO
        End Get
    End Property
End Class

Public Class TipoGasto
    Private drTipoGasto As dsCaja.CAJ_TIPOGASTORow
    Public Sub New(ByVal IdTipo As String)
        Try
            Dim daTipoGas As New dsCajaTableAdapters.CAJ_TIPOGASTOTableAdapter
            Dim dtTipoGas As dsCaja.CAJ_TIPOGASTODataTable = daTipoGas.GetDataByidTipoGasto(IdTipo)
            If dtTipoGas.Rows.Count > 0 Then
                drTipoGasto = dtTipoGas.Rows(0)
            Else
                Throw New Exception("Tipo Gasto no existe favor verificar e intentar de nuevo")
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public ReadOnly Property idTipoGasto() As String
        Get
            Return drTipoGasto.IDGASTO
        End Get
    End Property
    Public ReadOnly Property Descricion() As String
        Get
            Return drTipoGasto.DESCRIPCION
        End Get
    End Property
End Class

Public Class cCuadreCaja
    Private iCaja As cCaja
    Private lTotalGastos As Double = 0
    Private lTotalRC As Double = 0
    Private lTotalConsignaciones As Double = 0
    Private lTotalVentasContado As Double = 0
    Private lDesdeF As Date
    Private lHastaF As Date
    Public Sub New(ByVal IdCaja As String, ByVal HastaFecha As Date)
        Try
            iCaja = New cCaja(IdCaja)
            lDesdeF = iCaja.FechaUltimoCuadre
            lHastaF = HastaFecha
            Dim daGas As New dsCajaTableAdapters.CAJ_GASTOTableAdapter
            lTotalGastos = daGas.GetValorGastosByCajaFechas(IdCaja, lDesdeF, lHastaF)
            Dim daRC As New dsCarteraTableAdapters.CAR_RECIBOSCAJATableAdapter
            lTotalRC = daRC.GetVrRecibosByFechasCaja(lDesdeF, lHastaF, IdCaja)
            Dim daConsigna As New dsCajaTableAdapters.CAJ_CONSIGNATableAdapter
            lTotalConsignaciones = daConsigna.GetValorConsignaIdCajaFechas(lDesdeF, lHastaF, IdCaja)
            Dim daVentaContado As New dsMovimientoTableAdapters.MOV_MOVIMIENTOTableAdapter
            lTotalVentasContado = daVentaContado.GetValorFacturasByFechas(lDesdeF, lHastaF, IdCaja)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public Sub New(ByVal idCaja As String)
        Me.New(idCaja, Date.Today)
    End Sub

    Public ReadOnly Property FechaUltimoCuadre() As Date
        Get
            Return iCaja.FechaUltimoCuadre
        End Get
    End Property
    Public ReadOnly Property SaldoInicial() As Double
        Get
            Return iCaja.Saldo
        End Get
    End Property
    Public ReadOnly Property TotalConsignaciones() As Double
        Get
            Return lTotalConsignaciones
        End Get
    End Property
    Public ReadOnly Property TotalGastos() As Double
        Get
            Return lTotalGastos
        End Get
    End Property
    Public ReadOnly Property TotalRecibosCaja() As Double
        Get
            Return lTotalRC
        End Get
    End Property
    Public ReadOnly Property TotalVentasContado() As Double
        Get
            Return lTotalVentasContado
        End Get
    End Property
    Public ReadOnly Property SaldoCaja() As Double
        Get
            Return SaldoInicial + TotalVentasContado + TotalRecibosCaja - TotalGastos - TotalConsignaciones
        End Get
    End Property
    Public Sub CierreCaja()
        Try

        Catch ex As Exception

        End Try
    End Sub
    Public Function GetFactutasVentasContado() As dsMovimiento.MOV_MOVIMIENTODataTable

    End Function
    Public Function GetGastos() As dsCaja.CAJ_GASTODataTable

    End Function
End Class